package thread;

/**
 * 通过标志位来中断线程
 */
public class Demo6 {
    static int flag=0;
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(){
            @Override
            public void run() {
                while(flag==0){
                    System.out.println("转帐中");
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("已停止");
            }
        };
        t1.start();
        Thread.sleep(2000);//指的是当前线程
        System.out.println("停止转账");
        flag=1;
    }
}
